<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>注册 - layuiAdmin</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/lib/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/lib/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="/static/lib/layuiadmin/style/login.css" media="all">
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>云南紫米ERP</h2>
            <p>云南紫米ERP 官方出品的后台管理模板系统</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" name="userLoginpwd" id="LAY-user-login-password" lay-verify="pass"
                       placeholder="密码" class="layui-input" maxlength="32">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-repass"></label>
                <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="repass" placeholder="确认密码"
                       class="layui-input" maxlength="32">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="userName"></label>
                <input type="text" name="userName" id="userName" lay-verify="userName" placeholder="昵称"
                       class="layui-input" maxlength="50">
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-reg-submit">注 册</button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <label>社交账号注册</label>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>

                <a href="login.html" class="layadmin-user-jump-change layadmin-link layui-hide-xs">用已有帐号登入</a>
            </div>
        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">

        <p>© 2018 <a href="http://www.layui.com/" target="_blank">layui.com</a></p>
        <p>
            <span><a href="http://www.layui.com/admin/#get" target="_blank">获取授权</a></span>
            <span><a href="http://www.layui.com/admin/pro/" target="_blank">在线演示</a></span>
            <span><a href="http://www.layui.com/admin/" target="_blank">前往官网</a></span>
        </p>
    </div>

</div>

<script src="/static/lib/layuiadmin/layui/layui.js"></script>
<script>
    document.getElementById('userName').focus();

    layui.config({
        base: '/static/lib/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'user'], function () {
        var $ = layui.$
            , setter = layui.setter
            , admin = layui.admin
            , form = layui.form
            , router = layui.router();

        form.render();

        form.verify({
            pass: function (value) {
                if (!value || value.length == 0) {
                    return '请输入密码，密码为必须入力项目。'
                }
            },
            repass: function (value) {
                if (!value || value.length == 0) {
                    return '请输入确认密码，确认密码为必须入力项目。'
                }
            },
            userName: function (value) {
                if (!value || value.length == 0) {
                    return '请输入昵称，昵称为必须入力项目。'
                }
            },
        });

        //提交
        form.on('submit(LAY-user-reg-submit)', function (obj) {
            var field = obj.field;

            //确认密码
            if (field.userLoginpwd !== field.repass) {
                return layer.msg('两次密码输入不一致', {
                    anim: 6
                    , icon: 5
                    , time: 1000
                });
            }

            //请求接口
            $.ajax({
                url: '/registry/registry' //实际使用请改成服务端真实接口
                , data: field
                , method: 'post'
                , success: function (res) {
                    if (res.code == 0) {
                        layer.msg('注册成功', {
                            offset: '15px'
                            , icon: 1
                            , time: 1000
                        }, function () {
                            window.location.href = "/";
                        });
                    }
                }, error: function (res) {
                    return layer.msg(res.msg, {
                        anim: 6
                        , icon: 5
                        , time: 1000
                    });
                }
            });

            return false;
        });
    });
</script>
</body>
</html>